package com.xuelang.pipeline.artifact.infrastructure.resource.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.xuelang.pipeline.artifact.infrastructure.resource.dataobject.ArtifactUserDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 仓库用户数据Mapper
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Repository
public interface ArtifactUserMapper extends MPJBaseMapper<ArtifactUserDO> {

    /**
     * 批量插入仓库用户
     *
     * @param list
     * @return
     */
    @Insert({
		"<script> ",
		"INSERT INTO IM_OT_DO_ARTIFACT_USER ",
		"( ",
		"USER_NAME, USER_ID, ARTIFACT_ROLE_CODE, ARTIFACT_ROLE_ID, ARTIFACT_USER_NAME, ",
		"INSTANCE_REPOSITORY_NAME, ARTIFACT_USER_ID, ARTIFACT_USER_PASSWORD, ARTIFACT_TYPE, ARTIFACT_UUID, CREATOR_ID, UPDATER_ID ",
		") ",
		"VALUES ",
		"<foreach collection='list' item='item' separator=','> ",
		"( ",
		"#{item.userName}, #{item.userId}, #{item.artifactRoleCode}, #{item.artifactRoleId}, #{item.artifactUserName}, ",
		"#{item.instanceRepositoryName}, #{item.artifactUserId}, #{item.artifactUserPassword}, #{item.artifactType}, #{item.artifactUuid},", "#{item.creatorId}, #{item.updaterId} ",
		") ",
		"</foreach> ",
		"</script> ",
		})
    int insertBatch(@Param("list") List<ArtifactUserDO> list);
}
